package com.gzwh.v1.sysapi.conntroller;

import com.gzwh.v1.sysapi.bean.ResponseBean;
import com.gzwh.v1.sysapi.dao.UserMapper;
import com.gzwh.v1.sysapi.entity.UserBean;
import com.gzwh.v1.sysapi.exception.UnauthorizedException;
import com.gzwh.v1.sysapi.utils.JWTUtil;
import com.gzwh.v1.sysapi.utils.ReturnUtil;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@RestController
public class TestController {

//    @Autowired
//    UserMapper userMapper;

    @RequestMapping("/test/")
    @RequiresAuthentication
    public ResponseBean testMysql(){
        return new ResponseBean(200, "Login success", 123112);

    }

    @PostMapping("/login")
    public ResponseBean login(@RequestParam("username") String username,
                              @RequestParam("password") String password) {
//        UserBean userBean = userMapper.getUserBeanByName(username);
//        if (userBean.getPassword().equals(password)) {
//            return new ResponseBean(200, "Login success", JWTUtil.sign(username, password,"A"));
//        } else {
//            throw new UnauthorizedException("用户名或密码错误");
//
//        }
        return new ResponseBean(200, "Login success", 123112);

    }


    @RequestMapping(path = "/401")
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public ModelMap unauthorized() {
        return ReturnUtil.Success("操作成功", null, null);
    }


}
